<?php
function getRights($domain){

    $rights = array();
    
    $items = $domain::getItems();
    foreach ($items as $item) {
        $rights[$item] = Constants::$rights[$item]['name'];
    }
    
    return $rights;
}


function getDomainRights(&$form,&$availableRights,$activeRights,$domain) {

    if (!is_array($activeRights)) {
        $activeRights = array();
    }
    
    $string = "<li class='rights_header'>{$domain::$title}</li>";
    
    $rights = getRights($domain);
    foreach($rights as $id => $right) {
        
        if (isset(Constants::$rights[$id]['default'])) {
            continue;
        }
        
        $string .= "<li>";
        $string .= $form->checkbox('rights',array(
            'name' => "data[Role][rights][{$id}]",
            'id' => 'RoleRights'.$id,
            'hiddenField' => true,
            'disabled' => !in_array($id,$availableRights),
            'checked' => in_array($id,$activeRights)
        ));  
         
        $string .= $form->label('rights',$right);
        $string .= "</li>";
    }
    
    return $string;
}

?>

<table class="rights_panel">
    <tbody>
        <tr>
        <?php    
        foreach (Constants::$domains as $domain) {   
            echo "<td><ul>" . getDomainRights($this->Form,$availableRights,@$this->data['rights'],$domain) . "<ul></td>";
        } 
        ?>
        </tr>
    </tbody>
</table>
